package com.code.condition;

import com.code.bean.Phone;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

/**
 * @see org.springframework.context.annotation.ImportBeanDefinitionRegistrar#registerBeanDefinitions(AnnotationMetadata, BeanDefinitionRegistry)
 *
 * @author wangjie
 * @version V1.0
 * @date 2020/1/6
 */
public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    /**
     *
     * @param annotationMetadata 当前类的注解信息 {@link org.springframework.core.type.AnnotationMetadata}
     * @param beanDefinitionRegistry  beanDefinition注册类 {@link org.springframework.beans.factory.support.BeanDefinitionRegistry}
     */
    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) {

        boolean home = beanDefinitionRegistry.containsBeanDefinition("user");
        if(home){
            RootBeanDefinition beanDefinition = new RootBeanDefinition(Phone.class);
            beanDefinitionRegistry.registerBeanDefinition("phone",beanDefinition);
        }
    }
}
